import 'package:fl_location/fl_location.dart';
import 'package:flutter/cupertino.dart';
import 'package:gold/base/list_view_model.dart';
import 'package:gold/model/gold_recover_shop_model.dart';
import 'package:gold/utils/geocode/geocode_entity.dart';
import 'package:gold/utils/xfg_utils.dart';

/// @description: 店铺列表状态
/// @author tangzhentao
/// @created at 20:33 2024/12/10

class ShopListViewmodel extends ListViewModel<GoldRecoverShopModel> {
  /// 搜索内容
  final TextEditingController searchController = TextEditingController();
  final FocusNode searchNode = FocusNode();

  GeocodeEntity? _location;
  /// 地址信息
  GeocodeEntity? get location => _location;

  ShopListViewmodel(super.api);

  /// 获取定位信息
  Future getLocation() async {
    final location = await FlLocation.getLocation();
    _location = await geocodeCoordinate(location.latitude, location.longitude);
    setLoading();
    firstLoad();
  }

  @override
  Map<String, dynamic>? onOtherData() {
    return {
      "filter": {
        "keywords": '',
        "city": _location?.city,
        'lat': _location?.latitude,
        'lng': _location?.longitude,
      },
    };
  }

  @override
  void dispose() {
    searchController.dispose();
    searchNode.dispose();
    super.dispose();
  }
}